﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Studio77.GuessLyric.Pages;

namespace Studio77.GuessLyric.Views
{
    public partial class Keyboard : UserControl
    {
        public static Keyboard KeyboardInstance = null;

        List<KeyItem> keys = new List<KeyItem>();

        public Keyboard()
        {
            InitializeComponent();
            KeyboardInstance = this;
            foreach (var item in this.LayoutRoot.Children)
            {
                if (item is KeyItem)
                {
                    keys.Add(item as KeyItem);
                }
            }
        }

        public void OnKeyDown(KeyItem key)
        {
            GamePage.Instance.OnKeyboard(key);
            key.IsEnabled = false;
        }

        public void SetKeyBoardContent(List<String> keyContents)
        {
            if (keyContents.Count == 30)
            {
                //交换
                Random r = new Random(DateTime.Now.Millisecond);
                for (int i = 0; i < keyContents.Count; i++)
                {
                    int x = r.Next(keyContents.Count);
                    string temp = keyContents[i];
                    keyContents[i] = keyContents[x];
                    keyContents[x] = temp;
                }
                for (int i = 0; i < keyContents.Count; i++)
                {
                    keys[i].SetChar(keyContents[i]);
                    keys[i].IsEnabled = true;
                }
            }
        }

    }
}
